<template>
	<view class="content">
		<view class="item f-c-b">
			<view class="">身份证号</view>
			<input v-model="form.uidnumber" type="text" placeholder="请输入身份证号" placeholder-class="placCls" />
		</view>
		<view class="item f-c-b">
			<view class="">身份证姓名</view>
			<input v-model="form.uidname" type="text" placeholder="请输入身份证姓名" placeholder-class="placCls" />
		</view>
		<view class="item">
			<view class="">上传身份证照片</view>
			<view class="f">
				<view class="imgClass">
					<image class="imgListClass" v-for="(item,index) in imgList" :src="$u.baseUrl+item" mode="aspectFill"></image>
				</view>
				<view class="item_img f-c-c" v-show="imgList.length<2">
					<image @click="toUploadImg" src="../../static/index-cate/icon_jh.png" mode="widthFix"></image>
				</view>
			</view>
		</view>
		<view @click="toSubmit" class="btn f-c-c">提交</view>
	</view>

</template>

<script>
	import uploadImg from '../../utils/uploadImg/index.js'
	export default {
		data() {
			return {
				imgList:[],
				form:{
					uidnumber:'',
					uidname:''
				}
			}
		},
		methods: {
			async toUploadImg(){
				/* 1. 上传图片，获得转换好的地址 */
				const res = await uploadImg(this.$u.api.fileUpLoad, 2)
				console.log(res);
				res.forEach(item=>{
					this.imgList.push(item)
				})
			},
			async toSubmit(){
				if(!this.$u.test.idCard(this.form.uidnumber)){
					this.$u.toast('请输入正确的身份证号！')
					return
				}
				if(this.form.uidname==''){
					this.$u.toast('请输入身份证姓名！')
					return
				}
				if(this.imgList.length<2){
					this.$u.toast('请上传身份证正反照片！')
					return
				}
				let uidimg=this.imgList.flat()[0]+'|'+this.imgList.flat()[1]
				
				console.log(this.imgList.flat());
				const {success,msg}=await this.$u.api.addUAttestation({
					consumer:this.vuex_user.id,
					uidimg,
					uidname:this.form.uidname,
					uidnumber:this.form.uidnumber
				})
				if(success){
					this.$refs.uToast.show({
						title: msg,
						position: 'bottom'
					})
					 setInterval(()=>{
						 this.$back(1)
					 },1000)
				}else{
					this.$u.toast(msg)
				}
			}
		}
	}
</script>

<style>
	.content {
		height: 100vh;
		background-color: #F6F6F6;
	}

	.item {
		background-color: #FFFFFF;
		padding: 30rpx 20rpx;
		margin: 2rpx 0;
	}

	.item input {
		text-align: right;
	}

	.placCls {
		font-size: 30rpx;
		color: #999999;
	}
	.item_img{
		width: 160rpx;
		height: 160rpx;
		background-color: #EEEEEE;
		margin-top: 30rpx;
	}
	.item_img image{
		width: 62rpx;
	}
	.imgListClass{
		height: 160rpx;
		width: 160rpx;
		margin-right: 20rpx;
	}
	.imgClass{
		height: 160rpx;
		margin-top: 30rpx;
	}
	.btn{
		background-color: #FF8710;
		color: #FFFFFF;
		margin:500rpx 40rpx;
		padding: 20rpx;
		border-radius: 40rpx;
	}
</style>
